import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

/**
 * 这里放置一些公共组件
 */

/// 圆角矩形Container
class BorderRadiusContainer extends StatelessWidget {
  double width;
  double height;
  Color bgColor;
  Widget? child;
  EdgeInsetsGeometry? margin;

  BorderRadiusContainer(
      {Key? key,
      required this.width,
      required this.height,
      this.bgColor = Colors.white,
      this.margin,
      this.child})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
        child: child,
        margin: margin,
        //设置 child 居中
        alignment: const Alignment(0, 0),
        height: height,
        width: width,
        //边框设置
        decoration: const BoxDecoration(
          //背景
          color: Colors.white,
          //设置四周圆角 角度
          borderRadius: BorderRadius.all(Radius.circular(8.0)),
          //设置四周边框
        ));
  }
}

/// 圆角矩形图
class ClipRRectNetWorkImage extends StatelessWidget {
  String url;
  BoxFit boxFit;
  double radius;
  double? width, height;

  EdgeInsetsGeometry? margin;

  ClipRRectNetWorkImage(
      {Key? key,
      required this.url,
      required this.boxFit,
      required this.radius,
      this.width,
      this.height,
      this.margin})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
      margin: margin,
      width: width,
      height: height,
      child: ClipRRect(
        borderRadius: BorderRadius.circular(radius),
        child: Center(
          child: Image.network(url, fit: boxFit),
        ),
      ),
    );
  }
}

///圆形图片如：头像
class CircleNetworkImage extends StatelessWidget {
  String url;
  double width, height;
  BoxFit boxFit;

  CircleNetworkImage(
      {Key? key,
      required this.url,
      required this.boxFit,
      required this.height,
      required this.width})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return ClipOval(
      child: Container(
        color: Colors.red,
          child: Image.network(
        url,
        height: height,
        width: height,
        fit: boxFit,
      )),
    );
  }
}

///文本内容 Container（记得根据不同项目，修改文字颜色）
class ContentContainer extends StatelessWidget {
  String content;
  double? width;
  double? height;
  EdgeInsetsGeometry? margin;
  static const Color color = Colors.black87;

  ContentContainer({
    Key? key,
    required this.content,
    this.width,
    this.height,
    this.margin,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
      margin: margin,
      width: width,
      height: height,
      child: Text(
        content,
        style: const TextStyle(
          color: color,
          fontSize: 14,
        ),
      ),
    );
  }
}

///文本备注 Container（记得根据不同项目，修改文字颜色）
class NoteContainer extends StatelessWidget {
  String content;
  double? width;
  double? height;
  EdgeInsetsGeometry? margin;
  static const Color color = Colors.black54;

  NoteContainer({
    Key? key,
    required this.content,
    this.width,
    this.height,
    this.margin,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
      margin: margin,
      width: width,
      height: height,
      child: Text(
        content,
        style: const TextStyle(
          color: color,
          fontSize: 12,
        ),
      ),
    );
  }
}

///详情页标题(非继承AppBar)
class TitleBar extends StatelessWidget {
  String content;
  double height;
  static const Color color = Colors.black54;

  TitleBar({
    Key? key,
    required this.content,
    this.height = 70,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    // return Container(
    //   width: MediaQuery.of(context).size.width,
    //   height: height,
    //   child: Text(
    //     content,
    //     style: const TextStyle(
    //       color: color,
    //       fontSize: 12,
    //     ),
    //   ),
    // );

    return Container(
      color: Colors.white,
      child: Column(
        children: [
          Container(
            height: 30,
            color: Colors.white,
          ),
          Container(
            height: 40,
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Container(
                  child: const Icon(Icons.arrow_back_ios),
                  width: 7,
                  height: 20,
                  margin: const EdgeInsets.only(left: 8),
                ),
                Expanded(
                  child: Container(
                    color: Colors.white,
                    child: Text(
                      content,
                      textAlign: TextAlign.center,
                    ),
                  ),
                  flex: 1,
                ),
              ],
            ),
          )
        ],
      ),
    );
  }
}

///详情页标题
class TitleAppBar extends AppBar {
  TitleAppBar(BuildContext context, String titleName,
      {bool isCenterTitle = true,
      bool isBack = true,
      List<Widget>? actions,
      double fontSize = 16,
      FontWeight fontWeight = FontWeight.bold,
      Color foreColor = Colors.black,
      Color backgroundColor = Colors.white})
      : super(
            backgroundColor: backgroundColor,
            elevation: 0,
            title: Text(
              titleName,
              style: TextStyle(
                  color: foreColor, fontSize: fontSize, fontWeight: fontWeight),
            ),
            leading: Offstage(
              offstage: !isBack,
              child: IconButton(
                  iconSize: 20,
                  icon: Icon(
                    Icons.arrow_back_ios,
                    color: foreColor,
                  ),
                  onPressed: () => Navigator.pop(context)),
            ),
            actions: actions,
            centerTitle: isCenterTitle);
}

///左对齐标题
class LeftTitleBar extends StatelessWidget {
  String title;
  FontWeight fontWeight;
  static const Color color = Colors.black54;

  LeftTitleBar(
    this.title, {
    Key? key,
    this.fontWeight = FontWeight.w900,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Column(
      children: [
        Container(
          height: 30,
          color: Colors.white,
        ),
        Container(
          width: MediaQuery.of(context).size.width,
          decoration: const BoxDecoration(color: Color(0xffffffff)),
          child: SizedBox(
            child: Text(
              title,
              style: TextStyle(
                fontSize: 30,
                fontWeight: fontWeight,
                letterSpacing: 1.0,
              ),
            ),
          ),
          padding: const EdgeInsets.fromLTRB(15, 0, 0, 10),
        )
      ],
    );
  }
}
